<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>简单的计时</title>
</head>

<body>
  <button id="stop"> 暂停/继续</button>
  <input type="text" value="" id="time">
  <script>
    function timeOut(timeout) {
      setTimeout(() => {
        alert('欢迎光临美宜佳')
      }, timeout);
    }



    var c = 0;
    var t;
    function timedCount() {
      document.getElementById('time').value = c;
      c++;
      t = setTimeout(() => {
        timedCount();
      }, 1000);
    }

    var controller = true;
    var d = document.getElementById('stop');
    d.onclick = function () {
      controller = !controller;
      if (controller) {
        timedCount();
      } else {
        clearTimeout(t);
      }
    }
    timedCount();
  </script>
</body>

</html>